﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using CSCSN.DataAccess.Tool;
using CSCSN.EntitiyModels;
using CSCSN.ORM;
using CSCSN.ViewModels;
using CSCSN.ViewModelServices;
using CSCSN.WebApplication.BaseControllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.FlowAnalysis;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore;

namespace CSCSN.WebApplication.Controllers
{
    public class ApplicationTaskController : BasePaginationTemplateController<ApplicationTask, ApplicationTaskVM>
    {

        #region 控制器中需要的一些变量
        // public IViewModelService<ApplicationTask, ApplicationTaskVM> _service;
        static string taskTypeName;//任务类型的名称
        public ListPageParameter PaginateListPageParameter = new ListPageParameter(1, 10);//分页，1代表当前页数，10代表一页10条数据
        public ApplicationTaskController(IViewModelService<ApplicationTask, ApplicationTaskVM> service) : base(service)
        {
           
        }
        #endregion

        #region 任务分类显示的实现
        /// <summary>
        /// 没有用户登录时，启动此方法，得到的实体类数据是数据库所有的任务；用户登录后，启动此方法，得到的实体类数据是当前用户没有接取过的任务。
        /// </summary>
        /// <returns></returns>

        public virtual async Task<IActionResult> Index(string typeName)
        {
            taskTypeName = typeName;//将任务类型名称储存起来
            var boVMCollectionPending = await GetBoVMCollectionByTypeName();//取得符合条件的数据（条件：1、任务类型正确；2、用户没有接取过的任务；）
            var boVMCollection = IndexPaging("1", "10", boVMCollectionPending);//数据分页处理
            ViewData["PageGroup"] = PaginateListPageParameter.PagenateGroup;
            return View(boVMCollection);
        }
        /// <summary>
        /// 此处方法由ajax启动，是用户接取任务成功后，局部刷新页面
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <returns></returns>
        public virtual async Task<IActionResult> List(int pageIndex)
        {
            var boVMCollectionPending = await GetBoVMCollectionByTypeName();//取得符合条件的数据（条件：1、任务类型正确；2、用户没有接取过的任务；）
            var boVMCollection = IndexPaging(pageIndex.ToString(), "10", boVMCollectionPending);//数据分页处理
            ViewData["PageGroup"] = PaginateListPageParameter.PagenateGroup;
            return PartialView(boVMCollection);
        }
        /// <summary>
        ///此处方法由ajax启动，用户接取任务的具体实现
        /// </summary>
        /// <param name="id">任务id</param>
        /// <returns></returns>
        [Authorize(Roles = "Student")]//角色授权：角色类型为Student才能访问
        [HttpGet]
        public virtual async Task<IActionResult> UserAddTask(Guid id)
        {
            bool status = false;//预设事件完成状态为false
            var userIdentity = User.Identity;
            var user = await _service.EntityRepository.ApplicationUserManager.FindByNameAsync(userIdentity.Name);
            var task = _service.EntityRepository.EntitiesContext.ApplicationTasks.Find(id);
            var userWithTask = _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Where(s => s.ApplicationTasks == task && s.ApplicationUsers == user).FirstOrDefault();
            if (userWithTask == null)
            {
                var bo = new ApplicationUserWithApplicationTask()
                {
                    ApplicationUsers = user,
                    ApplicationTasks = task,
                };
                _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Add(bo);
                _service.EntityRepository.EntitiesContext.SaveChanges();
                return Json(status = true);
            }
            else
                return Json(status);

        }
        /// <summary>
        ///此处方法由ajax启动，用户取消任务的具体实现
        /// </summary>
        /// <param name="id">任务id</param>
        /// <returns></returns>
        [Authorize(Roles = "Student")]//角色授权：角色类型为Student才能访问
        [HttpGet]
        public virtual async Task<IActionResult> UserCancelTask(Guid id)
        {
            bool status = false;//预设事件完成状态为false
            var userIdentity = User.Identity;
            var user = await _service.EntityRepository.ApplicationUserManager.FindByNameAsync(userIdentity.Name);
            var task = _service.EntityRepository.EntitiesContext.ApplicationTasks.Find(id);
            var userWithTask = _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Where(s => s.ApplicationTasks == task && s.ApplicationUsers == user).FirstOrDefault();
            if (userWithTask != null)
            {
                _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Remove(userWithTask);
                int cood = _service.EntityRepository.EntitiesContext.SaveChanges();
                if (cood != 0) status = true;
                return Json(status);
            }
            else
                return Json(status);

        }
        /// <summary>
        /// 实现取得当前用户请求的数据
        /// </summary>
        /// <returns></returns>
        public virtual async Task<List<ApplicationTaskVM>> GetBoVMCollectionByTypeName()
        {

            List<ApplicationTaskVM> boVMCollection = new List<ApplicationTaskVM>();//用于存放视图页所需的数据
            var taskTypeID = _service.EntityRepository.EntitiesContext.ApplicationTaskTypes.Where(s => s.Name == taskTypeName).Select(s => s.Id).FirstOrDefault();//查询任务类型ID
            var taskAll = _service.EntityRepository.EntitiesContext.ApplicationTasks.Where(s => s.ApplicationTaskTypesID == taskTypeID).Include(s => s.ApplicationTaskTypes).Include(s=>s.ApplicationRole).Include(s=>s.TaskSites).ToList();//取出该类型下的所有任务数据(其中也包含了任务类型信息)
            var userIdentity = User.Identity;//取出浏览器的Cookie值
            if (userIdentity.Name == null)
            {
                foreach (var item in taskAll)
                {
                    boVMCollection.Add(ApplicationTaskToM(item));
                }
            }
            else
            {
                var user = await _service.EntityRepository.ApplicationUserManager.FindByNameAsync(userIdentity.Name);//查找当前登录用户
                var taskSet = _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Where(s => s.ApplicationUsers == user && s.ApplicationTasks.ApplicationTaskTypesID == taskTypeID).Include(s=>s.ApplicationTasks).Include(s=>s.ApplicationTasks.TaskSites).Include(s=>s.ApplicationTasks.ApplicationRole).Select(s=>s.ApplicationTasks).ToList();//查找前类型下哪些任务已被用户接取
                List<ApplicationTask> taskItem = new List<ApplicationTask>();//实例化一个List
                List<ApplicationTask> taskItemed = new List<ApplicationTask>();//实例化一个List(放已被接取的任务)
                int i = 0;//用于统计任务是否重复
                foreach (var item in taskAll)//将用户没有添加过的任务装进taskItem
                {
                    foreach (var receivedItem in taskSet)
                    {
                        if (item == receivedItem)
                        {
                            i++;
                        }
                    }
                    if (i ==0)
                    {
                        taskItem.Add(item);
                    }
                    else
                    {
                        taskItemed.Add(item);
                    }
                    i = 0;
                }
                foreach (var item in taskItem)
                {
                    boVMCollection.Add(ApplicationTaskToM(item));
                }
                foreach (var item in taskItemed)
                {
                    boVMCollection.Add(ApplicationTaskToMForSelected(item));
                }
            }
            boVMCollection = boVMCollection.OrderBy(s => s.BeginTime).ToList();
            int orderNumber = 0;
            foreach(var item in boVMCollection)
            {
                item.OrderNumber = (++orderNumber).ToString ();
            }
            return boVMCollection;
        }
        #endregion

        #region 对数据进行分页处理
        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页的数据行数</param>
        /// <param name="boVMCollectionPending">待分页的数据</param>
        /// <returns></returns>
        public List<ApplicationTaskVM> IndexPaging(string pageIndex, string pageSize, List<ApplicationTaskVM> boVMCollectionPending)
        {
            List<ApplicationTaskVM> boVMCollection = new List<ApplicationTaskVM>();
            int pageIndexS, pageSizeS;
            int.TryParse(pageIndex, out pageIndexS);
            int.TryParse(pageSize, out pageSizeS);
            int pageAll = (int)Math.Ceiling(boVMCollectionPending.Count / (double)pageSizeS);//计算分页的总页数
            if (pageIndexS > pageAll)
            {
                pageIndexS = pageAll;
            }
            boVMCollection = boVMCollectionPending.Skip((pageIndexS - 1) * pageSizeS).Take(pageSizeS).ToList();//把传入的数据进行分页处理
            PaginateListPageParameter.PagenateGroup = GetItem(pageAll, 5, pageIndexS);
            return boVMCollection;
        }

        /// <summary>
        /// 将分页导航按钮进行分组处理
        /// </summary>
        /// <param name="pageAll">分页的总数</param>
        /// <param name="counter">在分页器上显示页面导航按钮的个数</param>
        /// <param name="pageIndex">当前页码</param>
        /// <returns></returns>
        public static PagenateGroup GetItem(int pageAll, int counter, int pageIndex)
        {
            var pgItem = _GetCollection(pageIndex, pageAll, counter);
            var selectGroup = new PagenateGroup()
            {
                PageIndex = pageIndex,
                PageAmount = pageAll,
            };
            selectGroup.PagenateGroupItem = pgItem;
            return selectGroup;
        }

        /// <summary>
        /// 根据分页器所需要每一组显示的导航元素个数，将页码划分为相应的组
        /// </summary>
        /// <param name="pageAll">分页总数</param>
        /// <param name="counter">每一个分页组具有的分页导航按钮数（需为一个奇数）</param>
        /// <returns></returns>
        private static PagenateGroupItem _GetCollection(int pageIndex, int pageAll, int counter)
        {
            var pgItem = new PagenateGroupItem();
            int nuberm = (counter - 1) / 2;
            var firstIndex = pageIndex - nuberm;
            var lastIndex = pageIndex + nuberm;
            if (pageAll < counter)
            {
                firstIndex = 1;
                lastIndex = pageAll;
            }
            if (firstIndex < 1)
            {
                firstIndex = 1;
                lastIndex = counter;
            }
            if (lastIndex > pageAll)
            {
                firstIndex = pageAll - (counter - 1);
                lastIndex = pageAll;
            }
            pgItem.FirstIndex = firstIndex;
            pgItem.LastIndex = lastIndex;
            pgItem.ItemIndexAmount = counter;
            return pgItem;
        }

        #endregion

        #region 搜索功能（含分类筛选）
        /// <summary>
        /// 实现搜索时取得数据
        /// </summary>
        /// <returns></returns>
        public virtual async Task<List<ApplicationTaskVM>> GetBoVMCollectionByQuery()
        {

            List<ApplicationTaskVM> boVMCollection = new List<ApplicationTaskVM>();//用于存放视图页所需的数据
            var taskAll = _service.EntityRepository.EntitiesContext.ApplicationTasks.Include(s => s.ApplicationTaskTypes).Include(s => s.ApplicationRole).Include(s => s.TaskSites).ToList();//取出所有的任务数据
            var userIdentity = User.Identity;//取出浏览器的Cookie值
            if (userIdentity.Name == null)  //游客访问时
            {
                foreach (var item in taskAll)
                {
                    boVMCollection.Add(ApplicationTaskToM(item));
                }
            }
            else
            {
                var user = await _service.EntityRepository.ApplicationUserManager.FindByNameAsync(userIdentity.Name);//查找当前登录用户
                var taskSet = _service.EntityRepository.EntitiesContext.ApplicationUserWithApplicationTasks.Where(s => s.ApplicationUsers == user).Include(s => s.ApplicationTasks).Include(s => s.ApplicationTasks.TaskSites).Include(s => s.ApplicationTasks.ApplicationRole).Select(s => s.ApplicationTasks).ToList();//查找用户已经接取的任务
                List<ApplicationTask> taskItem = new List<ApplicationTask>();//实例化一个List
                List<ApplicationTask> taskItemed = new List<ApplicationTask>();//实例化一个List(放已被接取的任务)
                int i = 0;//用于统计任务是否重复
                foreach (var item in taskAll)//将用户没有添加过的任务装进taskItem
                {
                    foreach (var receivedItem in taskSet)
                    {
                        if (item == receivedItem)
                        {
                            i++;
                        }
                    }
                    if (i == 0)
                    {
                        taskItem.Add(item);
                    }
                    else
                    {
                        taskItemed.Add(item);
                    }
                    i = 0;
                }
                foreach (var item in taskItem)
                {
                    boVMCollection.Add(ApplicationTaskToM(item));
                }
                foreach (var item in taskItemed)
                {
                    boVMCollection.Add(ApplicationTaskToMForSelected(item));
                }
            }
            boVMCollection = boVMCollection.OrderBy(s => s.BeginTime).ToList();
            int orderNumber = 0;
            foreach (var item in boVMCollection)
            {
                item.OrderNumber = (++orderNumber).ToString();
            }
            return boVMCollection;
        }

        [HttpPost]
        public virtual async Task<IActionResult> TaskQuery(string keyWord)
        {
            if (string.IsNullOrEmpty(keyWord)) { keyWord = ""; }
            ViewBag.keyWord = keyWord;
            var boVMCollectionPending = await GetBoVMCollectionByQuery();//取得符合条件的数据
            boVMCollectionPending = boVMCollectionPending.Where(x => (((((x.Name.Contains(keyWord) || x.TaskSiteName.Contains(keyWord)) || x.Score.Contains(keyWord)) || x.Duration.Contains(keyWord)) || x.IssuerName.Contains(keyWord)) || x.ApplicationTaskTypeName.Contains(keyWord))).ToList();

            boVMCollectionPending = AssignmentForTaskVMSerialnumber(boVMCollectionPending);//处理视图模型数据的序号
            var boVMCollection = IndexPaging("1", "10", boVMCollectionPending);//数据分页处理
            ViewData["PageGroup"] = PaginateListPageParameter.PagenateGroup;
            ViewData["AllTaskSites"] = _service.EntityRepository.EntitiesContext.TaskSites.ToList();//所有的任务地点
            ViewData["AllIssuers"] = _service.EntityRepository.EntitiesContext.ApplicationRoles.Where(s => s.Name != "Student").ToList();//所有的任务发起人
            ViewData["AllTaskType"] = _service.EntityRepository.EntitiesContext.ApplicationTaskTypes.ToList();//所有的任务类型
            return View(boVMCollection);
        }
        
        public virtual async Task<IActionResult> TaskQueryList(int pageIndex, string taskQueryJson)
        {
            var taskQuery = new TaskQuery();
            taskQuery = Newtonsoft.Json.JsonConvert.DeserializeObject<TaskQuery>(taskQueryJson);


            if (string.IsNullOrEmpty(taskQuery.KeyWord)) { taskQuery.KeyWord = ""; }
            var boVMCollectionPending = await GetBoVMCollectionByQuery();//取得符合条件的数据
            boVMCollectionPending = boVMCollectionPending.Where(x => (((((x.Name.Contains(taskQuery.KeyWord) || x.TaskSiteName.Contains(taskQuery.KeyWord)) || x.Score.Contains(taskQuery.KeyWord)) || x.Duration.Contains(taskQuery.KeyWord)) || x.IssuerName.Contains(taskQuery.KeyWord)) || x.ApplicationTaskTypeName.Contains(taskQuery.KeyWord))).ToList();
            boVMCollectionPending = FilterData(taskQuery, boVMCollectionPending);//筛选数据

            boVMCollectionPending = AssignmentForTaskVMSerialnumber(boVMCollectionPending);//处理视图模型数据的序号
            var boVMCollection = IndexPaging(pageIndex.ToString(), "10", boVMCollectionPending);//数据分页处理
            ViewData["PageGroup"] = PaginateListPageParameter.PagenateGroup;
            ViewData["AllTaskSites"] = _service.EntityRepository.EntitiesContext.TaskSites.ToList();//所有的任务地点
            ViewData["AllIssuers"] = _service.EntityRepository.EntitiesContext.ApplicationRoles.Where(s => s.Name != "Student").ToList();//所有的任务发起人
            ViewData["AllTaskType"] = _service.EntityRepository.EntitiesContext.ApplicationTaskTypes.ToList();//所有的任务类型



            return PartialView("TaskQueryList", boVMCollection);
        }

        /// <summary>
        /// 筛选数据
        /// </summary>
        /// <param name="taskQuery">筛选条件</param>
        /// <param name="boVMCollectionPending">待筛选的数据</param>
        /// <returns></returns>
        public List<ApplicationTaskVM> FilterData(TaskQuery taskQuery, List<ApplicationTaskVM> boVMCollectionPending)
        {
            List<ApplicationTaskVM> boVMCollection = new List<ApplicationTaskVM>();
            if (taskQuery.TaskSite != "0")//地点筛选
            {
                boVMCollectionPending = boVMCollectionPending.Where(s => s.TaskSiteID == new Guid(taskQuery.TaskSite)).ToList();
            }
            if (taskQuery.TaskType != "0")//类型筛选
            {
                boVMCollectionPending = boVMCollectionPending.Where(s => s.ApplicationTaskTypesID == new Guid(taskQuery.TaskType)).ToList();
            }
            if (taskQuery.Score != "0" && taskQuery.Score != "undefined")//分值筛选
            {
                var score = taskQuery.Score;
                int scoreMin, scoreMax, scoreReality;
                if (score.Contains("以上"))
                {
                    int end = score.IndexOf("以");
                    int.TryParse(score.Substring(0, end), out scoreMin);
                    scoreMax = 999;
                }
                else
                {
                    int centre = score.IndexOf("-");
                    int.TryParse(score.Substring(0, centre), out scoreMin);
                    int.TryParse(score.Substring(centre + 1), out scoreMax);
                }
                List<ApplicationTaskVM> boVMCollectionTemporary = new List<ApplicationTaskVM>();
                foreach (var item in boVMCollectionPending)
                {
                    int end = item.Score.IndexOf("/");
                    int.TryParse(item.Score.Substring(0, end), out scoreReality);
                    if (scoreMin <= scoreReality && scoreReality <= scoreMax)
                    {
                        boVMCollectionTemporary.Add(item);
                    }
                }
                boVMCollectionPending = boVMCollectionTemporary;
            }
            if (taskQuery.Issuer != "0")//发起人筛选
            {
                boVMCollectionPending = boVMCollectionPending.Where(s => s.IssuerID == new Guid(taskQuery.Issuer)).ToList();
            }
            if (taskQuery.BeginTime != "不限")//开始时间筛选
            {
                var beginTime = taskQuery.BeginTime;
                DateTime aimBeginTime = DateTime.Parse("2011-11-11");
                if (beginTime=="今天")
                {
                    aimBeginTime = DateTime.Now;
                    boVMCollectionPending = boVMCollectionPending.Where(s => DateTime.Equals(s.BeginTime.Date, aimBeginTime.Date)).ToList();
                }
                if (beginTime == "明天")
                {
                    aimBeginTime = DateTime.Now;
                    aimBeginTime = aimBeginTime + new TimeSpan(1, 0, 0, 0);//今天+1
                    boVMCollectionPending = boVMCollectionPending.Where(s => DateTime.Equals(s.BeginTime.Date, aimBeginTime.Date)).ToList();
                }
                if (beginTime == "后天+")
                {
                    aimBeginTime = DateTime.Now;
                    aimBeginTime = aimBeginTime + new TimeSpan(2, 0, 0, 0);//今天+2
                    boVMCollectionPending = boVMCollectionPending.Where(s => DateTime.Compare(s.BeginTime.Date, aimBeginTime.Date)>=0).ToList();
                }
            }
            if (taskQuery.Duration != "不限")//时长筛选
            {
                var duration = taskQuery.Duration;
                int durationMin, durationMax, durationReality;
                if (duration.Contains("以上"))
                {
                    int end = duration.IndexOf("以");
                    int.TryParse(duration.Substring(0, end), out durationMin);
                    durationMax = 999;
                }
                else
                {
                    int centre = duration.IndexOf("-");

                    int.TryParse(duration.Substring(0, centre), out durationMin);
                    int.TryParse(duration.Substring(centre + 1), out durationMax);
                }
                List<ApplicationTaskVM> boVMCollectionTemporary = new List<ApplicationTaskVM>();
                foreach (var item in boVMCollectionPending)
                {
                    int end = item.Duration.IndexOf("/");
                    int.TryParse(item.Duration.Substring(0, end), out durationReality);
                    if (durationMin <= durationReality && durationReality <= durationMax)
                    {
                        boVMCollectionTemporary.Add(item);
                    }
                }
                boVMCollectionPending = boVMCollectionTemporary;
            }
            boVMCollection = boVMCollectionPending;
            return boVMCollection;
        }
        /// <summary>
        /// 为视图数据的序号赋有序值
        /// </summary>
        /// <param name="boVMCollection">序号待赋值的视图模型数据</param>
        /// <returns></returns>
        public List<ApplicationTaskVM> AssignmentForTaskVMSerialnumber( List<ApplicationTaskVM> boVMCollectionPending)
        {
           for (int i=0;i< boVMCollectionPending.Count;i++)
            {
                boVMCollectionPending[i].OrderNumber = (i + 1).ToString();
            }
            return boVMCollectionPending;
        }

        #endregion

        #region 暂留，作为参照
        ///// <summary>
        ///// 将分页导航按钮进行分组处理
        ///// </summary>
        ///// <param name="pageAll">分页的总数</param>
        ///// <param name="counter">在分页器上显示页面导航按钮的个数</param>
        ///// <param name="pageIndex">当前页码</param>
        ///// <returns></returns>
        //public static PagenateGroup GetItem(int pageAll, int counter, int pageIndex)
        //{
        //    var pgCollection = _GetCollection(pageAll, counter);
        //    var selectGroup = new PagenateGroup()
        //    {
        //        PageIndex = pageIndex,
        //        PageAmount = pageAll,
        //    };
        //    foreach (var item in pgCollection)
        //    {
        //        if (pageIndex >= item.FirstIndex && pageIndex <= item.LastIndex)
        //        {
        //            selectGroup.PagenateGroupItem = item;
        //        }
        //    }
        //    return selectGroup;
        //}

        ///// <summary>
        ///// 根据分页器所需要每一组显示的导航元素个数，将页码划分为相应的组
        ///// </summary>
        ///// <param name="pageAll">分页总数</param>
        ///// <param name="counter">每一个分页组具有的分页导航按钮数（需为一个奇数）</param>
        ///// <returns></returns>
        //private static List<PagenateGroupItem> _GetCollection( int pageAll, int counter)
        //{
        //    var pgCollection = new List<PagenateGroupItem>();

        //    int groupAmount = 0;               // 分组个数
        //    if (pageAll % counter == 0)
        //    {
        //        groupAmount = pageAll / counter;
        //    }
        //    else
        //    {
        //        groupAmount = pageAll/ counter + 1;
        //    }

        //    for (int i = 0; i < groupAmount; i++)
        //    {
        //        var firstIndex = (i * counter) + 1;
        //        var lastIndex = ((i + 1) * counter);
        //        if (lastIndex > pageAll)
        //            lastIndex = pageAll;

        //        pgCollection.Add(new PagenateGroupItem() { FirstIndex = firstIndex, LastIndex = lastIndex });

        //    }
        //    return pgCollection;
        //}
        #endregion 

        #region 数据映射
        private ApplicationTaskVM ApplicationTaskToM(ApplicationTask model)
        {
            ApplicationTaskVM item = new ApplicationTaskVM();
            item.Name = model.Name;
            item.TaskSiteID = model.TaskSites.Id;
            item.TaskSiteName = model.TaskSites.Name;
            item.Score = model.Score;
            item.BeginTime = model.BeginTime;
            item.IssuerID = model.IssuerID;
            item.IssuerName = model.ApplicationRole.Name;
            item.ApplicationTaskTypesID = model.ApplicationTaskTypesID;
            item.Id = model.Id;
            item.ApplicationTaskTypeName = model.ApplicationTaskTypes.Name;
            item.Duration = model.Duration;
            item.Description = "暂无";
            return item;
        }
        private ApplicationTaskVM ApplicationTaskToMForSelected(ApplicationTask model)//用户已接取的任务的转换
        {
            ApplicationTaskVM item = new ApplicationTaskVM();
            item.Name = model.Name;
            item.TaskSiteID = model.TaskSites.Id;
            item.TaskSiteName = model.TaskSites.Name;
            item.Score = model.Score;
            item.BeginTime = model.BeginTime;
            item.IssuerID = model.IssuerID;
            item.IssuerName = model.ApplicationRole.Name;
            item.ApplicationTaskTypesID = model.ApplicationTaskTypesID;
            item.Id = model.Id;
            item.ApplicationTaskTypeName = model.ApplicationTaskTypes.Name;
            item.Duration = model.Duration;
            item.Description = "暂无";
            item.IsSelected = true;
            return item;
        }
        #endregion


    }
   
}